<template>
	<el-container>
		<el-header class='x-header'>
			<b class="title">{{ page_info.title }}</b>
			<el-button v-if="$route.query.callback_url" size="mini" icon="el-icon-back" @click="g_page.funcBack">
				返回
			</el-button>
			<ExprotExcel api_url="/xadmin/app_car/app_car__sku__list/export" :api_data="form_q"></ExprotExcel>
			<el-button size="mini" type="success" icon="el-icon-edit" @click="g_page.funcRedirectEdit(`app_car__sku__edit`)">
				添加
			</el-button>
			<el-button size="mini" type="danger" icon="el-icon-delete" @click="g_page.funcDel()">删除</el-button>
			<el-button size="mini" icon="el-icon-refresh" @click="g_page.funcReload()">刷新</el-button>
		</el-header>
		<el-main class='x-main'>
			<el-form :inline="true" :model="form_q" size="mini">
				<el-form-item label="车牌号">
					<el-input v-model="form_q.compCarNo" placeholder="车牌号"></el-input>
				</el-form-item>
				<el-form-item label="设备号">
					<el-input v-model="form_q.compDeviceNo" placeholder="设备号"></el-input>
				</el-form-item>
				<el-form-item label="车型">
					<el-select filterable clearable v-model="form_q.spu_id" placeholder="请选择">
						<el-option v-for="item in page_info.list_spu"
								   :label="item.cspu_name"
								   :key="item.cspu_id"
								   :value="item.cspu_id">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="网点">
					<el-select filterable clearable v-model="form_q.network_id" placeholder="请选择">
						<el-option v-for="item in page_info.list_network"
								   :label="item.cnetwork_name"
								   :key="item.cnetwork_id"
								   :value="item.cnetwork_id">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="g_page.funcSearch">搜索</el-button>
				</el-form-item>
			</el-form>
			<div class="table-wrap">
				<el-table stripe ref="multipleTable" tooltip-effect="dark"
						  @selection-change="g_page.funcTableSelectionChange"
						  :data="list_data">
					<el-table-column type="selection"></el-table-column>
					<el-table-column label="ID">
						<template slot-scope="data">
							<div v-html="data.row.id"></div>
						</template>
					</el-table-column>
					<el-table-column label="车型">
						<template slot-scope="data">
							<div v-html="data.row.cspu_name"></div>
						</template>
					</el-table-column>
					<el-table-column label="图片">
						<template slot-scope="data">
							<CompImg :img_root="page_info.static_file_root" :img_val="data.row.csku_pic"></CompImg>
						</template>
					</el-table-column>
					<el-table-column label="车牌">
						<template slot-scope="data">
							<div v-html="data.row.csku_car_no"></div>
						</template>
					</el-table-column>
					<el-table-column label="终端号">
						<template slot-scope="data">
							<div v-html="data.row.csku_device_no"></div>
						</template>
					</el-table-column>
					<el-table-column label="备注">
						<template slot-scope="data">
							<div v-html="data.row.csku_remak"></div>
						</template>
					</el-table-column>
					<el-table-column label="状态">
						<template slot-scope="data">
							<SkuState :sku="data.row" style="font-size: 12px;"></SkuState>
						</template>
					</el-table-column>
					<el-table-column label="信息">
						<template slot-scope="data">
							<SkuInfo :sku="data.row" style="font-size: 12px;"></SkuInfo>
						</template>
					</el-table-column>
					<el-table-column label="当前停放网点">
						<template slot-scope="data">
							<div v-if="data.row.csku_real_cnetwork_id!=''">{{ data.row.cnetwork_name }}</div>
							<div style="color:red;" v-else>暂无</div>
						</template>
					</el-table-column>
					<el-table-column label="锁定状态">
						<template slot-scope="data">
							<div v-if="!data.row.lock">正常</div>
							<div style="font-size: 12px;" v-else>
								<div>被锁定</div>
								<div>解锁时间：{{ data.row.csku_lock_timeout }}</div>
							</div>
						</template>
					</el-table-column>
					<el-table-column label="上下架">
						<template slot-scope="data">
							<div v-if="data.row.csku_enable==1">上架</div>
							<div style="color: red;" v-else>
								下架
							</div>
							<el-button type="text" size="mini" @click="funcSetEnable(data.row)">
								<span v-if="data.row.csku_enable==1">设置下架</span>
								<span v-else>
									设置上架
								</span>
							</el-button>
						</template>
					</el-table-column>
					<el-table-column fixed="right" width="200" label="操作">
						<template slot-scope="data">
							<el-button type="text" size="mini" @click="g_page.funcRedirectEdit('app_car__sku__edit',data.row)">
								编辑
							</el-button>
							<el-button v-if="data.row.csku_lock_network==1" type="text" size="mini" @click="g_page.funcRedirectEdit(`app_car__sku_network__list?sku_id=${data.row.id}`)">
								指定还车网点
							</el-button>
						</template>
					</el-table-column>
				</el-table>
			</div>
		</el-main>
		<!---->
		<!---->
		<!-- 分页 -->
		<el-footer v-if="page_show" class="x-page">
			<el-pagination class="paging" background layout="total, sizes, prev, pager, next, jumper"
						   @current-change="g_page.funcPageChange" :page-sizes="[page_size]"
						   :current-page="page_index" :page-size="page_size" :total="page_total">
			</el-pagination>
		</el-footer>
		<!---->
		<!---->
		<!-- 弹框 -->
		<el-dialog :title="form.app_idx+'配置'" :visible.sync="form_dialog_visible" width="70%">
			<el-form ref="form" :rules="form_rules" :model="form" size="mini" label-width="15%">
				<el-form-item label="入口链接" v-if="!g_page.funcIsAdminAdd()">
					<el-input :disabled="true" v-model="form.oauth_url"/>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="g_page.funcBack" size="mini">取消</el-button>
				<el-button type="success" @click="g_page.funcSave" size="mini">保存</el-button>
			</div>
		</el-dialog>
		<!---->
		<!---->
		<!---->
	</el-container>
</template>


<script>
	import SkuInfo from '@/views/app_wxapp/app_car/components/SkuInfo'
	import SkuState from '@/views/app_wxapp/app_car/components/SkuState'
	import ExprotExcel from '@/components/ExprotExcel'

	export default {
		components: {
			SkuInfo,
			SkuState,
			ExprotExcel
		},
		data() {
			let page_data = { super_uid: '' }
			//
			page_data = this.g_cc.funcGetInitData(page_data)
			//
			return page_data
		},
		mounted() {
			console.log('mounted')
			//
			this.g_page.funcSetVue(this)
			// 应用ID
			this.g_page.funcSetApiUrlList('/xadmin/app_car/app_car__sku__list')
			this.g_page.funcSetApiUrlDel('/xadmin/app_car/app_car__sku__list/del')
			//页码
			this.g_page.funcSetPageSize(20)
			//搜索
			this.form_q = {
				'compKw': ''
			}
			this.g_page.funcGetList()
			//
			this.form_rules = {
				acc_uidX: [
					{
						required: true,
						message: '必填',
						trigger: 'blur'
					}
				]
			}
			//
		},
		methods: {
			//上下架
			funcSetEnable(row) {
				let page = this
				let enable = 0
				if (row.csku_enable == 0) {
					enable = 1
				}
				this.g_cc.func_confirm('确定？', () => {
					// debugger
					this.g_cc.func_axios({
						url: '/xadmin/app_car/app_car__sku__list/funcSetEnable',
						data: {
							sku_id: row.csku_id,
							enable: enable
						},
						success: (res) => {
							//
							if (res.data.errcode == 0) {
								this.g_cc.func_alert('设置成功', 'success', () => {
									this.g_page.funcGetList()
								})
							} else {
								this.g_cc.func_alert(res.data.errmsg, 'error')
							}
						}
						//
					})
				})
				//////////
			}
			/////////////////////////
			////////////////////
		}
	}
</script>


